Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
yamlify-object
Advanced tools
Stringify object/array with yaml syntax
npm install yamlify-object
const yamlifyObject = require('yamlify-object');
const obj = {
array: [
2,
'two',
{
emptyArray: [],
},
],
error: new Error('message'),
date: new Date(0),
object: {
number: 200,
bool: false,
null: null,
undefined: undefined,
emptyObject: {},
},
};
const formattedString = yamlifyObject(obj, {
indent: ' ',
prefix: '\n',
postfix: '\n',
});
console.log(formattedString);
/*
array:
- 2
- two
- emptyArray: []
error: Error: message
date: new Date(1970-01-01T00:00:00.000Z)
object:
number: 200
bool: false
null: null
undefined: undefined
emptyObject: {}
*/
Type: Object
Array
Type: string
Default: ' '
- signle space
Type: string
Default: '\n'
Type: string
Default: ''
Type: Function
Expected to return a string
that stringified version of Date instance.
Type: Function
Expected to return a string
that stringified version of Error instance.
Type: object
Default:
{
date: function (s: string): string,
error: function (s: string): string,
symbol: function (s: string): string,
string: function (s: string): string,
number: function (s: string): string,
boolean: function (s: string): string,
null: function (s: string): string,
undefined: function (s: string): string,
}
Each property of colors object expected to be a function
that
expected to return somehow colorified version of passed string
argument.
You can specify colors only for types you need and the rest will stay colorless strings:
const obj = {
number: 1
string: 'str',
bool: true,
};
const formattedString = yamlifyObject(obj, {
colors: {
number: (value) => `COLOR_CODE${value}COLOR_CODE`,
boolean: (value) => `COLOR_CODE${value}COLOR_CODE`,
},
});
console.log(formattedString);
/*
number: COLOR_CODE1COLOR_CODE
string: str
bool: COLOR_CODEtrueCOLOR_CODE
*/
For terminal can be used yamlify-object-colors preset:
FAQs
Stringify object/array with yaml syntax
The npm package yamlify-object receives a total of 2,954 weekly downloads. As such, yamlify-object popularity was classified as popular.
We found that yamlify-object demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.